package com.example.demo.servers;

import com.example.demo.domain.Girl;
import com.example.demo.enums.ResultEnum;
import com.example.demo.exception.GirlException;
import com.example.demo.repository.GirlRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

@Service
public class GirlServers {
    @Autowired
    private GirlRepository girlRepository;
    @Transactional
    public  void insertTwo(){
        Girl girl1=new Girl();
        girl1.setCupSize("A");
        girl1.setAge(15);
        girlRepository.save(girl1);
        Girl girl2=new  Girl();
        girl2.setAge(16);
        girl2.setCupSize("B");
        girlRepository.save(girl2);

    }
    public  void getAge( Integer id) throws Exception{
        Girl girl=girlRepository.findOne(id);
        Integer age=girl.getAge();
        if(age<10){
            //返回："你还在上小学吧" code:99
            throw  new GirlException(ResultEnum.PRIMARY_SCHOOL);

        }else if(age>10 && age<16){
                //返回："你还在初中吧" code:100
            throw  new GirlException(ResultEnum.MIDDLE_SCHOOL);
        }


    }
}
